package com.cd.learn.cdlearn.resttemplate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author YeePongWong
 * @version 1.0
 * @date 2020/4/3 2:58 下午
 */
@Component
public class ZipkinTraceIdFilter implements Filter {


    private static final Logger log = LoggerFactory.getLogger(ZipkinTraceIdFilter.class);


    @Value("${spring.application.name}")
    private String applicationName;
    @Value("${server.port}")
    private String port;

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        if(httpServletRequest.getRequestURI().contains("receive")){
            chain.doFilter(request, response);
            return;
        }


        long l = System.currentTimeMillis();
        TestContext.set(l+"");
        System.out.println("设置的为"+l);
        chain.doFilter(request, response);
        TestContext.remove();

    }


    @Override
    public void destroy() {
        log.info("stopping......");
    }

}
